//
//  PayRecordController.m
//  Lead
//
//  Created by shouhan on 2018/8/31.
//  Copyright © 2018年 陈永发. All rights reserved.
//

#import "PayRecordController.h"
#import "PayPreCell.h"
#import "ShareProfitModel.h"

@interface PayRecordController ()<UITableViewDelegate,UITableViewDataSource>
{
    int pageindex;
}
@property (weak, nonatomic) IBOutlet UITableView *payTableView;

@property (nonatomic, strong) NSMutableArray * arrDataSource;

@end

@implementation PayRecordController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.payTableView registerNib:[UINib nibWithNibName:@"PayPreCell" bundle:nil] forCellReuseIdentifier:@"PayPreCell"];

    self.bottomLayout.constant = KNAVIGATIONBARHEIGHT;
    
    pageindex = 1;
    [self getIntegralDetailList:YES];
    self.payTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refresh)];
    
    self.payTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arrDataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    PayPreCell * cell  = [tableView dequeueReusableCellWithIdentifier:@"PayPreCell"];
    
    cell.payModel = self.arrDataSource[indexPath.row];
    return cell;
}

-(void)refresh
{
    pageindex = 1;
    [self getIntegralDetailList:YES];
}
-(void)loadMore
{
    pageindex ++;
    [self getIntegralDetailList:NO];
}

- (void)getIntegralDetailList:(BOOL)isRefresh{
    
    [MyDataService requestAFURL:[NSString stringWithFormat:KCommission, 2,pageindex,20] httpMethod:@"GET" params:nil data:nil complection:^(id result) {
        
        if (isRefresh) {
            [self.arrDataSource removeAllObjects];
        }
        if ([result[@"success"] boolValue] == YES) {
            [self.arrDataSource addObjectsFromArray:[ShareProfitModel mj_objectArrayWithKeyValuesArray:result[@"data"]]];
        }
        
        [self.payTableView reloadData];
        [self.payTableView.mj_header endRefreshing];
        [self.payTableView.mj_footer endRefreshing];
        
    } failure:^(id erro) {
        [self.payTableView.mj_header endRefreshing];
        [self.payTableView.mj_footer endRefreshing];
    }];
    
    
    
}

- (NSMutableArray *)arrDataSource{
    if (!_arrDataSource) {
        _arrDataSource = [NSMutableArray array];
    }
    
    return _arrDataSource;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
